//
//  BaseViewController.swift
//  KKWB
//
//  Created by KSY-iOS on 17/1/7.
//  Copyright © 2017年 KK. All rights reserved.
//

import UIKit

class BaseViewController: UITableViewController {

    var visitorView: VisitorView = VisitorView.visitorView();
    
    var isLogin: Bool = UserAccountViewModel.shareInstance.isLogin
    
    override func loadView() {
        
        isLogin ? super.loadView() : setupVisitorView()
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        setupNavigationItems()
    }

    

}
// MARK:- 设置UI界面
extension BaseViewController {

    // 设置访客视图
    fileprivate func setupVisitorView() {
        
        self.view = visitorView
        
        visitorView.registerBtn .addTarget(self, action: #selector(BaseViewController.registerItemClick), for: .touchUpInside)
        visitorView.loginBtn.addTarget(self, action: #selector(BaseViewController.loginItemClick), for: .touchUpInside)
    }
    
    // 设置导航栏左右的item
    fileprivate func setupNavigationItems() {
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .plain, target: self, action: #selector(BaseViewController.registerItemClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .plain, target: self, action: #selector(BaseViewController.loginItemClick))
    }
    
}

// MARK:- 时间监听
extension BaseViewController {
    
    @objc fileprivate func registerItemClick() {
        
    }
    
    @objc fileprivate func loginItemClick() {
        
        let oauth = OAuthViewController()
        let oauthNav = UINavigationController(rootViewController: oauth)
        
        present(oauthNav, animated: true, completion: nil)
        
        
    }
}

